package demo.zyy.com.dreamstudio.utils;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import demo.zyy.com.dreamstudio.R;


/**
 * Created on 2017/8/1
 * by -zy
 */

public enum ToastEnum {

    builder;
    private View mRootView;
    private ImageView mToast_image;
    private TextView mToast_text;
    private Toast mToast;
    private Context mContext;

    public void init(Context context){
        this.mContext=context;
        mToast=new Toast(context);

    }
    public void show(CharSequence msg){
        if(!TextUtils.isEmpty(msg)){
            this.mRootView= LayoutInflater.from(mContext).inflate(R.layout.toast_layout2,null);
            this.mToast_image= (ImageView) mRootView.findViewById(R.id.toast_image);
            this.mToast_text= (TextView) mRootView.findViewById(R.id.toast_tv);
            mRootView.getBackground().setAlpha(77);
            mToast_image.setVisibility(View.GONE);
            mToast_text.setText(msg);
            mToast.setGravity(Gravity.CENTER,0,0);
            mToast.setView(mRootView);
            mToast.show();
        }
    }
    public void showTime(CharSequence msg,int duration) {
        if (!TextUtils.isEmpty(msg)) {
            this.mRootView= LayoutInflater.from(mContext).inflate(R.layout.toast_layout2,null);
            this.mToast_image= (ImageView) mRootView.findViewById(R.id.toast_image);
            this.mToast_text= (TextView) mRootView.findViewById(R.id.toast_tv);
            mRootView.getBackground().setAlpha(77);
            mToast_image.setVisibility(View.GONE);
            mToast_text.setText(msg);
            mToast.setDuration(duration);
            mToast.setGravity(Gravity.CENTER, 0, 0);
            mToast.setView(mRootView);
            mToast.show();
        }
    }
    public void showPicture(CharSequence msg,int image) {
        if (!TextUtils.isEmpty(msg)) {
            this.mRootView= LayoutInflater.from(mContext).inflate(R.layout.toast_addtolike,null);
            this.mToast_image= (ImageView) mRootView.findViewById(R.id.toast_image);
            this.mToast_text= (TextView) mRootView.findViewById(R.id.toast_tv);
            mRootView.getBackground().setAlpha(204);
            mToast_image.setVisibility(View.VISIBLE);
            mToast_image.setImageResource(image);
            mToast_text.setText(msg);
            mToast.setGravity(Gravity.CENTER, 0, 0);
            mToast.setView(mRootView);
            mToast.show();
        }
    }
    public void showTimePicture(CharSequence msg,int image,int duration) {
        if (!TextUtils.isEmpty(msg)) {
            this.mRootView= LayoutInflater.from(mContext).inflate(R.layout.toast_addtolike,null);
            this.mToast_image= (ImageView) mRootView.findViewById(R.id.toast_image);
            this.mToast_text= (TextView) mRootView.findViewById(R.id.toast_tv);
            mRootView.getBackground().setAlpha(204);
            mToast_image.setVisibility(View.VISIBLE);
            mToast_image.setImageResource(image);
            mToast_text.setText(msg);
            mToast.setDuration(duration);
            mToast.setGravity(Gravity.CENTER, 0, 0);
            mToast.setView(mRootView);
            mToast.show();
        }
    }

}
